﻿namespace AgileBoard.Domain
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Iesi.Collections.Generic;
    using SharpArch.Core.DomainModel;

    [Serializable]
    public class Release : Entity
    {
        private ISet<Feature> _features = new HashedSet<Feature>();
        private ISet<Iteration> _iterations = new HashedSet<Iteration>();

        /// <summary>
        /// Created Date
        /// </summary>
        public virtual DateTime CreateTime { get; set; }

        /// <summary>
        /// Created by
        /// </summary>
        public virtual string Creator { get; set; }

        /// <summary>
        /// Release ID
        /// </summary>
        public virtual Guid ReleaseID { get; set; }

        /// <summary>
        /// Project ID
        /// </summary>
        public virtual Guid ProjectID { get; set; }

        /// <summary>
        /// Release name
        /// </summary>
        public virtual string Name { get; set; }

        /// <summary>
        /// Release period start date
        /// </summary>
        public virtual DateTime PeriodFrom { get; set; }

        /// <summary>
        /// Release period end date
        /// </summary>
        public virtual DateTime PeriodTo { get; set; }

        public virtual ReadOnlyCollection<Feature> Features
        {
            get { return new List<Feature>(_features).AsReadOnly(); }
        }

        public virtual ReadOnlyCollection<Iteration> Iterations
        {
            get { return new List<Iteration>(_iterations).AsReadOnly(); }
        }

        public virtual void AddFeature(Feature feature)
        {
            feature.ReleaseID = ReleaseID.ToString();
            _features.Add(feature);
        }

        public virtual void RemoveFeature(Feature n)
        {
        }

        public virtual void AddIteration(Iteration iteration)
        {
            iteration.ReleaseID = ReleaseID;
            _iterations.Add(iteration);
        }

        public virtual void RemoveIteration(Iteration item)
        {
            _iterations.Remove(item);
        }
    }
}